
#pragma once

//Defines 2D matrix with special methods for saddle point finding.
template <class T>
struct matrix
{
	private:
		size_t width, height;
		T *data;
	public:
		//Creates matrix with required size.
		matrix(size_t width, size_t height)
		{
			this->width = width;
			this->height = height;
			this->data = new T[width * height];
		}
		//Returns width of this matrix.
		inline size_t getWidth()
		{ return width; }
		//Returns height of this matrix.
		inline size_t getHeight()
		{ return height; }
		//Finds and returns minimal value of required row.
		inline T findRowMinimum(size_t row)
		{
			T minimum = (*this)(row, 0);
			for (size_t j = 1; j < getWidth(); j++)
				if (minimum > (*this)(row, j))
					minimum = (*this)(row, j);
			return minimum;
		}
		//Finds and returns maximal value of required column.
		inline T findColumnMaximum(size_t column)
		{
			T maximum = (*this)(0, column);
			for (size_t i = 1; i < getHeight(); i++)
				if (maximum < (*this)(i, column))
					maximum = (*this)(i, column);
			return maximum;
		}
		//Returns element, that is allocated at intersection of i-row with j-column.
		inline T &operator() (size_t i, size_t j)
		{ return data[j + i * width]; }
		//Matrix, you are free!
		~matrix()
		{ SAFE_DELETE_ARRAY(data); }
};

//Auxiliary class, that defines bundle of one-type elements.
template <class T>
struct point
{
	public:
		T x, y;

		inline point()
		{ /*nothing*/ }

		inline point(T x, T y)
		{
			this->x = x;
			this->y = y;
		}
};
